import { Component, OnInit, ViewChild } from '@angular/core';
import { _HttpClient, ModalHelper }     from '@delon/theme';
import { STColumn, STComponent, STReq } from '@delon/abc';
import { SFDateWidgetSchema, SFSchema } from '@delon/form';

@Component({
    selector   : 'app-manager-order',
    templateUrl: './order.component.html',
})
export class ManagerOrderComponent implements OnInit
{
    url = `api/orders/page`;
    searchSchema: SFSchema = {
        properties: {
            opName     : {
                type : 'string',
                title: '',
                ui   : {
                    placeholder: '城市、商家、设备、交易人员',
                    width      : 260,
                },
            },
            createdDate: {
                type : 'string',
                title: '时间',
                ui   : {
                    widget   : 'date',
                    mode     : 'range',
                    showToday: true,
                } as SFDateWidgetSchema,
            }
        },
    };
    @ViewChild('st', { static: false }) st: STComponent;
    columns: STColumn[] = [
        {
            title: '单号', index: 'ordersId'
        },
        { title: '省份', index: 'provinceName' },
        { title: '城市', index: 'cityName' },
        {
            title: '交易时间',
            index: 'createdDate',
            type : 'date',
            sort : { reName: { ascend: 'asc', descend: 'desc' } },
        },
        {
            title : '支付方式', index: 'orderType',
            type  : 'tag', tag: {
                'weixin': { text: '微信支付', color: 'green' },
                'alipay': { text: '支付宝', color: 'blue' },
            },
            filter: {
                multiple: false,
                menus   : [ { text: '微信', value: 'weixin' }, { text: '支付宝', value: 'alipay' } ],
            },
        },
        { title: '商家', index: 'storeName' },
        // { title: '操作员', index: 'opName' },
        { title: '设备名称', index: 'deviceName' },
        { title: '售价', index: 'amount', type: 'currency' },
        {
            title    : '支付状态', index: 'status', type: 'tag', tag: {
                0: { text: '未支付', color: 'red' },
                1: { text: '已支付', color: 'geekblue' },
            }, filter: {
                multiple: false,
                menus   : [ { text: '未支付', value: 0 }, { text: '已支付', value: 1 } ],
            },
        },
    ];
    
    req: STReq = {
        params: {
            isCashOut: false,
            sort     : 'createdDate,desc',
        }
    };
    
    statistics = { count: 0, total: 0, profit: 0 };
    
    constructor( private http: _HttpClient, private modal: ModalHelper )
    {
    }
    
    
    export()
    {
    
    }
    
    reload( value )
    {
        this.st.reset(value, { merge: true })
    }
    
    ngOnInit(): void
    {
        this.http.get("api/orders/order-statistics").subscribe(value =>
        {
            this.statistics = value
        })
    }
}
